//
//  ZYSCellModels.m
//  budejie
//
//  Created by oldSix_Zhu on 16/8/28.
//  Copyright © 2016年 oldSix_Zhu. All rights reserved.
//

#import "ZYSCellModels.h"
#import <AFNetworking.h>

@implementation ZYSCellModels

+(instancetype)ZYSCellModelsWithDic:(NSDictionary *)dic
{
    ZYSCellModels *model = [[ZYSCellModels alloc]init];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
//    if ([key isEqualToString:@"id"])
//    {
//        self.ID = value;
//    }
}

+(void)loadCellWithUrlStr:(NSString *)urlStr successBlock:(void(^)(NSArray *array))successBlock failBlock:(void(^)(NSError *error))failBlock
{
    [[AFHTTPSessionManager manager]GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSArray *arr = dic[@"list"];
        
        NSMutableArray *mArr = [NSMutableArray arrayWithCapacity:arr.count];
        
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           
            ZYSCellModels *model = [self ZYSCellModelsWithDic:obj];
            
            [mArr addObject:model];
            
        }];
        
        if (successBlock)
        {
            successBlock(mArr.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failBlock)
        {
            failBlock(error);
        }
    }];
    
}


@end











